<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta content="telephone=no,email=no" name="format-detection">
    <link rel="stylesheet" href="./resource/CSS/LoginPage/LoginPlusRegister.css">
    <link rel="stylesheet" href="resource/CSS/global.css">
    <title>游戏开发(肥宅)社的抢课系统Demo α版本</title>
</head>
    <script src="./resource/js/flexible.js"></script>
    <script src="./resource/js/LoginAndRegiste.js"></script>
    <script src="./resource/js/libraries/jquery/jquery-3.3.1.min.js"></script>
<body>
<header>
    <div class="login-header"  onclick="addHref(this)" href="">
        <p class="login-back_sign">游戏开发(肥宅)社的抢课系统Demo α版本</p>
    </div>
</header>

<div class="html-content">

    <div class="login-main">
        <nav class="login-nav">
            <div class="login-logo"><img src="./resource/image/LoginPage/logo-img.png" alt=""></div>
        </nav>
        <form class="login-main_box" action="" onsubmit="return startTheNewWorld()" method="post">
            <div class="box-input_area">
                <img src="./resource/image/LoginPage/user-img.png" alt="" class="input-image">
                <input class="login-control" type="text" id="login-input_username" placeholder="您的正方账号" name="username"  required oninvalid="setCustomValidity('请输入正方账号');" oninput="setCustomValidity('');">
                <img src="./resource/image/LoginPage/user-img_focus.png" alt="" class="input-image input-image_focus">
            </div>
            <div class="box-input_area">
                <img src="./resource/image/LoginPage/password-img.png" alt="" class="input-image">
                <input class="login-control" type="password" autocomplete="off" id="login-input_password" placeholder="密码" name="password" required oninvalid="setCustomValidity('请输入密码');" oninput="setCustomValidity('');">
                <img src="./resource/image/LoginPage/password-img_focus.png" alt="" class="input-image input-image_focus">
                <img src="./resource/image/LoginPage/eye-img-close.png" id="login-input_password-btn" class="input-image password-eye_btn" alt="" onclick="hideShowPsw()">
            </div>

            <input class="login-login_btn" type="submit" value="登 录">
            <!--<div class="login-main_option">&#45;&#45;%>-->
            <!--<div class=" option-left option"><a href="registe.do">注册账号</a></div>-->
            <!--<div class=" option-right option"><a href="retrievePsw.do">忘记密码</a></div>-->

        </form>

    </div>
</div>
</body>
<script>
    window.onload = function () {
        $.ajax({
            type:"get",
            url: "/loginServlet",
            dataType: "json",
            scriptCharset: "utf-8",
            success: function (data) {
                console.log(data);
                if(data["username"]!=null)
                    $("#login-input_username").val(data["username"]);
                if(data["password"]!=null)
                    $("#login-input_password").val(data["password"]);
            }
        });
    }


    function addHref(obj) {
        var href = obj.getAttribute("href");
        location.href= href;
    }

    function startTheNewWorld() {
        var username = $("#login-input_username").val();
        var password = $("#login-input_password").val();
        $(".login-back_sign").text("正在登录中....");
        $.ajax({
            type:"post",
            url: "/loginServlet",
            dataType: "json",
            scriptCharset: "utf-8",
            data:{
                username:username,
                password:password
            },
            success: function (data) {
                if(data["susscessUrl"]!=null)
                    window.location.href = data["susscessUrl"];
                $(".login-back_sign").text(data["message"]);
            }
        });
        return false;
    }
</script>
</html>
